package cn.hinglo.gameclaw.admin.action;

import cn.hinglo.gameclaw.admin.service.OderService;
import cn.hinglo.gameclaw.data.controller.BaseController;
import cn.hinglo.gameclaw.data.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @createTime: 2018/1/2
 * @author: HingLo
 * @description: 订单管理类
 */
@RestController
@RequestMapping("admin/o/")
public class OrderAction extends BaseController {

    private final OderService oderService;

    @Autowired
    public OrderAction(OderService oderService) {
        this.oderService = oderService;
    }


    /**
     * 订单管理，订单列表
     *
     * @param status 订单状态（待发货，待收货，已收货)
     * @return 订单列表
     */
    @GetMapping("list")
    public Result listOrder(@RequestParam("status") int status, int page, int size) {
        return oderService.listOderService(status, page, size);
    }

    /**
     * 删除订单信息
     *
     * @param id 订单编号
     * @return 删除结果
     */
    @DeleteMapping("delete")
    public Result deleteOrder(@RequestParam("id") String id) {
        return oderService.deleteOderService(id);
    }

    /**
     * 订单状态标记
     *
     * @param id     订单的唯一Id
     * @param status 标记的状态
     * @return 标记结果
     */
    @PutMapping("mark")
    public Result endOder(@RequestParam("id") String id, @RequestParam("status") int status) {
        return oderService.endOderService(id, status);
    }

    /**
     * 填写订单的物流编号
     *
     * @param id  订单
     * @param gid 物流编号
     * @return 结果
     */
    @PutMapping("update")
    public Result update(String id, String gid) {
        return oderService.updateGidService(id, gid);
    }

    /**
     * 物流订单的明细
     *
     * @param type 订单类型
     * @param date 订单时间
     * @return 返回结果
     */
    @GetMapping("orderDetail")
    public Result orderDetail(int type, @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
        return oderService.orderDetailService(type, date);
    }
}
